package com.tailyou.androidlearning202400.act

import android.os.Bundle
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.viewpager2.widget.ViewPager2
import com.tailyou.androidlearning202400.R
import com.tailyou.androidlearning202400.adapter.AdapterWelcome


class WelcomeActivity : AppCompatActivity() {
    // 声明组件
    private lateinit var vpWelcome: ViewPager2

    // 引导页用到的图片资源
    private var imgRes = mutableListOf<Int>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        this.enableEdgeToEdge()
        setContentView(R.layout.activity_welcome)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v: View, insets: WindowInsetsCompat ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        // 找到分页组件
        vpWelcome = findViewById(R.id.vpWelcome)
        // 准备图片资源
        imgRes.add(R.mipmap.w1)
        imgRes.add(R.mipmap.w2)
        imgRes.add(R.mipmap.w3)
        imgRes.add(R.mipmap.w4)
        // 创建Adapter实例
        val adapter = AdapterWelcome(imgRes);
        vpWelcome.adapter = adapter
    }
}